package com.jingwu.example.service

import com.jingwu.example.repository.*
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.Spy
import org.spockframework.spring.SpringBean
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification

/**
 * <p> The @SpringBean can not working with @InjectMocks </p>
 * but can work with @Resource or @Autowired, see {@link com.jingwu.example.service.UserServiceTest}
 *
 * @author 菁芜
 * @since 2021/11/23 - 16:41
 */
@ContextConfiguration
class OtherServiceTest extends Specification {
    @Mock
    private UserRepository userRepository;
    @Spy
    private DummyRepository dummyRepository;

    @SpringBean
    private FakeRepository fakeRepository = Mock();

    @MockBean
    private MockRepository mockRepository;

    @Mock
    private ActivityRepository activityRepository;

    @InjectMocks
    OtherService service


    def setup() {
        MockitoAnnotations.initMocks(this)
    }

    def cleanup() {
    }

    def "test doSomething"() {
        service.doSomething()

        expect:
        with(service) {
            service.userRepository != null
            service.dummyRepository != null
            service.mockRepository != null
            service.activityRepository != null
            service.fakeRepository == null
        }
    }
}
